package lyq.spec.edu.week12_home01;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class WeChatAdapter extends ArrayAdapter {

        private final int resourceId;

        public WeChatAdapter(Context context, int textViewResourceId, List<Wechat> objects) {

            super(context, textViewResourceId, objects);

            resourceId = textViewResourceId;

        }

        @Override

        public View getView(int position, View convertView, ViewGroup parent) {

            Wechat wecht = (Wechat) getItem(position); // 获取当前Wechat项的实例

            View view = LayoutInflater.from(getContext()).inflate(resourceId, null);//实例化一个对象

            ImageView wechtImage = (ImageView) view.findViewById(R.id.wechat_image);//获取该布局内的图片视图

            TextView wechtName = (TextView) view.findViewById(R.id.wechat_name);

            TextView wechtText = (TextView) view.findViewById(R.id.wechat_text);//获取该布局内的文本视图

            wechtImage.setImageResource(wecht.getImageId());//为图片视图设置图片资源

            wechtName.setText(wecht.getName());

            wechtText.setText(wecht.getText());//为文本视图设置文本内容

            return view;

        }

    }

